var postData = require('../../data/data.js')
var app=getApp()
var base = require('../../conf.js')
Page({
  data: {
    swiper_img:[],
    imgPath:base.imgPath,
    items:[],
    items1:[]
  },
  onLoad(){
    this.getSliderImgs()
    this.getHotItems()
    this.getWorthItems()
  },
  toDetail: function (e) {
    var gid = e.currentTarget.dataset.id
    wx.navigateTo({
      url: "/pages/detail/index" +'?'+ 'gid='+gid
    })
  },
  getSliderImgs: function () {
    var self = this;
    wx.request({
      url: base.url + '/banner',
      method: 'get',
      header: {
        "Content-Type": "application/json;charset=UTF-8",
        'userToken': base.token_Date
      },
      success: function (res) {
        console.log(res.data.data)
        self.setData({
          swiper_img:res.data.data
        })
      }
    })
  },
  getSliderImgs: function () {
    var self = this;
    wx.request({
      url: base.url + '/banner',
      method: 'get',
      header: {
        "Content-Type": "application/json;charset=UTF-8",
        'userToken': base.token_Date
      },
      success: function (res) {
        console.log(res.data.data)
        self.setData({
          swiper_img: res.data.data
        })
      }
    })
  },
  getWorthItems: function () {
    var self = this;
    wx.request({
      url: base.url + '/seller',
      data: { params: { isRecommend: 0 } },
      method: 'get',
      header: {
        "Content-Type": "application/json;charset=UTF-8",
        'userToken': base.token_Date
      },
      success: function (res) {
        var worthItems = self.getItem(res.data.data)
        self.setData({
          worthItems: worthItems
        })
      }
    })
  },
  getHotItems: function () {
    var self = this;
    wx.request({
      url: base.url + '/seller',
      data: { params: { isRecommend: 1 }},
      method: 'get',
      header: {
        "Content-Type": "application/json;charset=UTF-8",
        'userToken': base.token_Date
      },
      success: function (res) {
        var hotItems = self.getItem(res.data.data)
        self.setData({
          hotItems: hotItems
        })
      }
    })
  },
  getItem(Item){
    for(var i=0;i<Item.length;++i){
      Item[i].img = Item[i].img.split(",")[0]
    }
    return Item
  },
  toOrder:function(e){
    wx.navigateTo({
      url: "/pages/home-page/order"
    })
  }
})